<template>
	<view class="page">
		<view class="tabs">
			<view class="tabs-item flex--aj-center" v-for="(item,index) in tabsList" :key="index"
				@click="tabClick(item,index)">
				<view class="item-content flex--aj-center"
					:class="{'item-content-no': index !== tabCurrent,'item-content-active': index === tabCurrent}">
					{{item.text}}
					<view class="item-img" v-if="index === tabCurrent">
						<image src="../../../static/icon/order_tab.png" mode=""></image>
					</view>
				</view>
			</view>
		</view>

		<view class="list" v-if="list.length > 0">
			<view class="li" :style="{'backgroundImage': 'url('+couponBg+')'}" v-for="(item,index) in list"
				:key="index">
				<view class="li-left">
					<view class="ll-price">
						<text>￥</text>{{ item.money }}
					</view>
					<view class="ll-text">
						满{{ item.limit }}可用
					</view>
				</view>
				<view class="li-right">
					<view class="lr-content">
						<view class="lr-title text-cut">
							{{ item.name }}
						</view>
						<view class="lr-desc">
							<view v-if="item.range">
								{{ item.range }}
							</view>
							<view class="m-t-10">
								{{ item.validity }}
							</view>
						</view>
					</view>
					<!-- <view class="lr-btn" @click="receive(item)">
						立即领取
					</view> -->
				</view>
			</view>
		</view>

		<view v-else>
			<view class="empty" v-if="show">
				<view class="empty-text">
					暂时没有数据
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tabCurrent: 0,
				tabsList: [{
						text: '未使用',
						status: 1
					},
					{
						text: '已使用',
						status: 2
					},
				],
				list: [],
				couponBg: this.domainUrl + '/assets/img/uniapp/coupon/coupon_bg.png',
				page: 1,
				pageSize: 10,
				last_page: 1,
				show: false
			}
		},
		onLoad() {
			this.getList()
		},
		onReachBottom() {
			let _this = this;
			// 已经是最后一页
			if (_this.page >= _this.last_page) {
				return false;
			}

			_this.page++
			_this.getList()
		},
		methods: {
			tabClick(item, index) {
				let _this = this
				if (_this.tabCurrent == index) {
					return false
				}

				_this.tabCurrent = index
				_this.page = 1
				_this.last_page = 1
				_this.list = []
				_this.show = false
				_this.getList()
			},
			getList() {
				let _this = this
				_this.$api.get('meet.coupon/userCoupon', {
					page: _this.page,
					page_size: _this.pageSize,
					status: _this.tabsList[_this.tabCurrent].status
				}).then(res => {
					_this.show = true
					if (res.code == 1) {
						let list = _this.list.concat(res.data.data)

						_this.list = list

						_this.last_page = res.data.last_page
					}
				}, fail => {})
			},
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F6F6F6;
		padding-bottom: 80rpx;
	}

	.flex--aj-center {
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.m-t-5 {
		margin-top: 5rpx;
	}

	.m-t-10 {
		margin-top: 10rpx;
	}

	.text-cut {
		text-overflow: -o-ellipsis-lastline;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		line-clamp: 2;
		-webkit-box-orient: vertical;
	}

	.tabs {
		background-color: #FFFFFF;
		display: flex;
		align-items: center;

		.tabs-item {
			width: 50%;

			.item-content {
				width: 120rpx;
				height: 92rpx;
				position: relative;

				.item-img {
					position: absolute;
					top: 20%;
					left: 0;
					width: 120rpx;
					height: 65rpx;

					image {
						width: 100%;
						height: 100%;
					}
				}
			}

			.item-content-no {
				font-weight: 400;
				font-size: 32rpx;
				color: #8A8A8A;
			}

			.item-content-active {
				font-weight: 800;
				font-size: 36rpx;
				color: #000000;
			}
		}
	}


	.list {
		padding: 32rpx 24rpx;
		// margin-top: 32rpx;
	}

	.list .li {
		width: 100%;
		height: 180rpx;
		border-radius: 16rpx;
		background-position: center;
		background-size: cover;
		background-repeat: no-repeat;
		background-size: 100%;
		overflow: hidden;
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin-bottom: 24rpx;
	}

	.li .li-left {
		width: 28%;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		color: #FFFFFF;
	}

	.li-left .ll-price {
		font-size: 64rpx;
	}

	.li-left .ll-price text {
		font-size: 28rpx;
	}

	.li-left .ll-text {
		font-size: 28rpx;
	}

	.li .li-right {
		width: 67%;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.li-right .lr-title {
		color: #333333;
		font-size: 32rpx;
		font-weight: bold;
	}

	.li-right .lr-desc {
		margin-top: 8rpx;
		color: #999999;
		font-size: 20rpx;
	}

	.li-right .lr-btn {
		width: 108rpx;
		height: 48rpx;
		background: #FF0000;
		border-radius: 110rpx;
		color: #FFFFFF;
		font-size: 20rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		margin-right: 32rpx;
	}

	.li-right .lr-content {
		width: calc(100% - 108rpx - 35rpx);
	}

	.empty {
		width: 100%;
		text-align: center;
		margin-top: 40%;

		image {
			width: 200rpx;
			height: 200rpx;
		}

		.empty-text {
			font-size: 32rpx;
			color: #999999;
			margin-top: 80rpx;
		}
	}
</style>